<?php

namespace Modules\Taxonomy\Library;

use Phalcon\Di;
use Modules\Xunsearch\Library\Xunsearch;
use Modules\Taxonomy\Entity\Term;

class Search
{
    public static function xunsearchGenerateProjectFile()
    {
        $di = Di::getDefault();
        $field = $di->getShared('entityManager')->field('term');
        $state = Xunsearch::formFieldToIni($field, WEB_CODE . '_term');
        if ($state) {
            return true;
        } else {
            return false;
        }
    }

    public static function source($page = 1)
    {
        $data = Term::find([
            'sort' => [
                'changed' => -1,
            ],
            'limit' => 30,
            'skip' => 30 * ($page - 1),
        ]);
        return $data;
    }

    public static function total()
    {
        return Term::count();
    }
}